package ru.amse.tsyganov.jumleditor.view.activity;

import java.util.Collections;
import java.util.List;

import org.eclipse.swt.graphics.GC;

import ru.amse.tsyganov.jumleditor.graphicaleditor.Coordinates;
import ru.amse.tsyganov.jumleditor.model.activity.FinalState;
import ru.amse.tsyganov.jumleditor.model.common.GraphModel;
import ru.amse.tsyganov.jumleditor.properties.StringProperty;
import ru.amse.tsyganov.jumleditor.validator.Problem;
import ru.amse.tsyganov.jumleditor.view.ViewVisitor;
import ru.amse.tsyganov.jumleditor.view.activepoints.ActivePoint;
import ru.amse.tsyganov.jumleditor.view.common.GraphView;
import ru.amse.tsyganov.jumleditor.view.common.StateView;

public class FinalStateView<T extends FinalState> extends StateView<T> {
	
	private static final int INNER_CIRCLE_DIAMETER = 25;
	
	private static final int OUTER_RING_THICKNESS = 3;
	
	private final List<ActivePoint> points;
	
	public FinalStateView(T model, 
			GraphView<? extends GraphModel> activityGraphView) {
		
		super(model, activityGraphView);
		
		setWidth(INNER_CIRCLE_DIAMETER);
		setHeight(INNER_CIRCLE_DIAMETER);
		
		points = createNominalActivePoints();
	}
	
	@Override
	public void accept(ViewVisitor v) {
		v.visitFinalStateView(this);
		visitTransitions(v);
	}
	
	@Override
	public void paintFigure(GC gc, Coordinates coordinates) {
		assert gc != null;
		
		gc.setBackground(getValidity().getColor());
		
		gc.fillOval(
				coordinates.fromModelXToScreenX(getX() + OUTER_RING_THICKNESS), 
				coordinates.fromModelYToScreenY(getY() + OUTER_RING_THICKNESS), 
				getWidth() - 2 * OUTER_RING_THICKNESS + 1, 
				getHeight() - 2 * OUTER_RING_THICKNESS + 1);
		
		gc.setForeground(getValidity().getColor());
		
		gc.drawOval(
				coordinates.fromModelXToScreenX(getX()), 
				coordinates.fromModelYToScreenY(getY()), getWidth(), getHeight());
	}
	
	@Override
	public List<ActivePoint> getActivePoints() {
		if (getSelectedItems().selectedStatesContains(this)) {
			return points;
		} else {
			return Collections.emptyList();
		}
	}
	
	@Override
	public StringProperty getMainProperty() {
		return null;
	}

	public String getClassName() {
		return "FinalStateView";
	}

	@Override
	public List<Problem> getInnerProblems() {
		return Collections.emptyList();
	}
	
}
